﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace WCFService.Labb1
{
    public class CityDataTable
    {
        private List<City> citiesToVisit { get; set; }
        List<City> cityList = null;

        public CityDataTable()
        {
            cityList = new List<City>();

            //all cities and their "roads"
            List<Neighbor> nbUlrisehamnList = new List<Neighbor>();
            nbUlrisehamnList.Add(new Neighbor() { Name = "Viskafors", Distance = 6 });
            nbUlrisehamnList.Add(new Neighbor() { Name = "Boras", Distance = 8 });
            nbUlrisehamnList.Add(new Neighbor() { Name = "Dalsjofors", Distance = 4 });
            nbUlrisehamnList.Add(new Neighbor() { Name = "Hokerum", Distance = 5 });
            nbUlrisehamnList.Add(new Neighbor() { Name = "Kartholmen", Distance = 22 });
            var ulrisehamnEntity = new City { Name = "Ulricehamn", Neighbors = nbUlrisehamnList };
            cityList.Add(ulrisehamnEntity);

            List<Neighbor> nbViskaforsList = new List<Neighbor>();
            nbViskaforsList.Add(new Neighbor() { Name = "Ulricehamn", Distance = 6 });
            nbViskaforsList.Add(new Neighbor() { Name = "Dalsjofors", Distance = 3 });
            nbViskaforsList.Add(new Neighbor() { Name = "Fristad", Distance = 5 });
            nbViskaforsList.Add(new Neighbor() { Name = "Boras", Distance = 3 });
            nbViskaforsList.Add(new Neighbor() { Name = "Sandared", Distance = 8 });
            nbViskaforsList.Add(new Neighbor() { Name = "Fristla", Distance = 3 });
            var viskaforsEntity = new City { Name = "Viskafors", Neighbors = nbViskaforsList };
            cityList.Add(viskaforsEntity);

            List<Neighbor> nbDalsjoforsList = new List<Neighbor>();
            nbDalsjoforsList.Add(new Neighbor() { Name = "Ulricehamn", Distance = 4 });
            nbDalsjoforsList.Add(new Neighbor() { Name = "Viskafors", Distance = 3 });
            nbDalsjoforsList.Add(new Neighbor() { Name = "Hokerum", Distance = 4 });
            nbDalsjoforsList.Add(new Neighbor() { Name = "Boras", Distance = 6 });
            var dalsjoforsEntity = new City { Name = "Dalsjofors", Neighbors = nbDalsjoforsList };
            cityList.Add(dalsjoforsEntity);

            List<Neighbor> nbHokerumList = new List<Neighbor>();
            nbHokerumList.Add(new Neighbor() { Name = "Ulricehamn", Distance = 5 });
            nbHokerumList.Add(new Neighbor() { Name = "Dalsjofors", Distance = 4 });
            nbHokerumList.Add(new Neighbor() { Name = "Fristad", Distance = 3 });
            nbHokerumList.Add(new Neighbor() { Name = "Annelund", Distance = 6 });
            nbHokerumList.Add(new Neighbor() { Name = "Kartholmen", Distance = 8 });
            var hokerumEntity = new City { Name = "Hokerum", Neighbors = nbHokerumList };
            cityList.Add(hokerumEntity);

            List<Neighbor> nbFristlaList = new List<Neighbor>();
            nbFristlaList.Add(new Neighbor() { Name = "Viskafors", Distance = 3 });
            nbFristlaList.Add(new Neighbor() { Name = "Boras", Distance = 11 });
            nbFristlaList.Add(new Neighbor() { Name = "Bollebygd", Distance = 15 });
            nbFristlaList.Add(new Neighbor() { Name = "Kinna", Distance = 8 });
            var fristlaEntity = new City { Name = "Fristla", Neighbors = nbFristlaList };
            cityList.Add(fristlaEntity);

            List<Neighbor> nbBorasList = new List<Neighbor>();
            nbBorasList.Add(new Neighbor() { Name = "Fristla", Distance = 11 });
            nbBorasList.Add(new Neighbor() { Name = "Viskafors", Distance = 3 });
            nbBorasList.Add(new Neighbor() { Name = "Ulricehamn", Distance = 8 });
            nbBorasList.Add(new Neighbor() { Name = "Dalsjofors", Distance = 6 });
            nbBorasList.Add(new Neighbor() { Name = "Fristad", Distance = 7 });
            nbBorasList.Add(new Neighbor() { Name = "Sandared", Distance = 5 });
            nbBorasList.Add(new Neighbor() { Name = "Bollebygd", Distance = 7 });
            nbBorasList.Add(new Neighbor() { Name = "Kinna", Distance = 14 });
            var borasEntity = new City { Name = "Boras", Neighbors = nbBorasList };
            cityList.Add(borasEntity);

            List<Neighbor> nbFristadList = new List<Neighbor>();
            nbFristadList.Add(new Neighbor() { Name = "Boras", Distance = 7 });
            nbFristadList.Add(new Neighbor() { Name = "Viskafors", Distance = 5 });
            nbFristadList.Add(new Neighbor() { Name = "Hokerum", Distance = 3 });
            nbFristadList.Add(new Neighbor() { Name = "Annelund", Distance = 10 });
            nbFristadList.Add(new Neighbor() { Name = "Allingsas", Distance = 25 });
            nbFristadList.Add(new Neighbor() { Name = "Sandared", Distance = 9 });
            var fristadEntity = new City { Name = "Fristad", Neighbors = nbFristadList };
            cityList.Add(fristadEntity);

            List<Neighbor> nbAnnelundList = new List<Neighbor>();
            nbAnnelundList.Add(new Neighbor() { Name = "Fristad", Distance = 10 });
            nbAnnelundList.Add(new Neighbor() { Name = "Hokerum", Distance = 6 });
            nbAnnelundList.Add(new Neighbor() { Name = "Kartholmen", Distance = 5 });
            nbAnnelundList.Add(new Neighbor() { Name = "Vargarda", Distance = 10 });
            nbAnnelundList.Add(new Neighbor() { Name = "Allingsas", Distance = 13 });
            nbAnnelundList.Add(new Neighbor() { Name = "Tollsjo", Distance = 12 });
            var annelundEntity = new City { Name = "Annelund", Neighbors = nbAnnelundList };
            cityList.Add(annelundEntity);

            List<Neighbor> nbKartholmenList = new List<Neighbor>();
            nbKartholmenList.Add(new Neighbor() { Name = "Annelund", Distance = 5 });
            nbKartholmenList.Add(new Neighbor() { Name = "Hokerum", Distance = 8 });
            nbKartholmenList.Add(new Neighbor() { Name = "Ulricehamn", Distance = 22 });
            nbKartholmenList.Add(new Neighbor() { Name = "Vargarda", Distance = 8 });
            nbKartholmenList.Add(new Neighbor() { Name = "Allingsas", Distance = 7 });
            var kartholmenEntity = new City { Name = "Kartholmen", Neighbors = nbKartholmenList };
            cityList.Add(kartholmenEntity);

            List<Neighbor> nbKinnaList = new List<Neighbor>();
            nbKinnaList.Add(new Neighbor() { Name = "Fristla", Distance = 8 });
            nbKinnaList.Add(new Neighbor() { Name = "Boras", Distance = 14 });
            nbKinnaList.Add(new Neighbor() { Name = "Sandared", Distance = 31 });
            nbKinnaList.Add(new Neighbor() { Name = "Bollebygd", Distance = 21 });
            var kinnaEntity = new City { Name = "Kinna", Neighbors = nbKinnaList };
            cityList.Add(kinnaEntity);

            List<Neighbor> nbSandaredList = new List<Neighbor>();
            nbSandaredList.Add(new Neighbor() { Name = "Kinna", Distance = 31 });
            nbSandaredList.Add(new Neighbor() { Name = "Viskafors", Distance = 8 });
            nbSandaredList.Add(new Neighbor() { Name = "Boras", Distance = 5 });
            nbSandaredList.Add(new Neighbor() { Name = "Fristad", Distance = 9 });
            nbSandaredList.Add(new Neighbor() { Name = "Vargarda", Distance = 14 });
            nbSandaredList.Add(new Neighbor() { Name = "Tollsjo", Distance = 40 });
            nbSandaredList.Add(new Neighbor() { Name = "Bollebygd", Distance = 15 });
            var sanadredEntity = new City { Name = "Sandared", Neighbors = nbSandaredList };
            cityList.Add(sanadredEntity);

            List<Neighbor> nbVargardaList = new List<Neighbor>();
            nbVargardaList.Add(new Neighbor() { Name = "Sandared", Distance = 14 });
            nbVargardaList.Add(new Neighbor() { Name = "Annelund", Distance = 10 });
            nbVargardaList.Add(new Neighbor() { Name = "Kartholmen", Distance = 8 });
            nbVargardaList.Add(new Neighbor() { Name = "Allingsas", Distance = 10 });
            var vargardaEntity = new City { Name = "Vargarda", Neighbors = nbVargardaList };
            cityList.Add(vargardaEntity);

            List<Neighbor> nbBollebygdList = new List<Neighbor>();
            nbBollebygdList.Add(new Neighbor() { Name = "Kinna", Distance = 21 });
            nbBollebygdList.Add(new Neighbor() { Name = "Fristla", Distance = 15 });
            nbBollebygdList.Add(new Neighbor() { Name = "Boras", Distance = 7 });
            nbBollebygdList.Add(new Neighbor() { Name = "Sandared", Distance = 15 });
            nbBollebygdList.Add(new Neighbor() { Name = "Tollsjo", Distance = 8 });
            var bollebygdEntity = new City { Name = "Bollebygd", Neighbors = nbBollebygdList };
            cityList.Add(bollebygdEntity);

            List<Neighbor> nbTollsjoList = new List<Neighbor>();
            nbTollsjoList.Add(new Neighbor() { Name = "Bollebygd", Distance = 8 });
            nbTollsjoList.Add(new Neighbor() { Name = "Sandared", Distance = 40 });
            nbTollsjoList.Add(new Neighbor() { Name = "Annelund", Distance = 12 });
            nbTollsjoList.Add(new Neighbor() { Name = "Allingsas", Distance = 13 });
            var tollsjoEntity = new City { Name = "Tollsjo", Neighbors = nbTollsjoList };
            cityList.Add(tollsjoEntity);

            List<Neighbor> nbAllingsasList = new List<Neighbor>();
            nbAllingsasList.Add(new Neighbor() { Name = "Tollsjo", Distance = 13 });
            nbAllingsasList.Add(new Neighbor() { Name = "Fristad", Distance = 25 });
            nbAllingsasList.Add(new Neighbor() { Name = "Annelund", Distance = 13 });
            nbAllingsasList.Add(new Neighbor() { Name = "Kartholmen", Distance = 7 });
            nbAllingsasList.Add(new Neighbor() { Name = "Vargarda", Distance = 10 });
            var allingsasEntity = new City { Name = "Allingsas", Neighbors = nbAllingsasList };
            cityList.Add(allingsasEntity);
        }

        public string[] getCitiesNames()
        {
            List<City> cityList = GetCities();
            string[] citiesNames = new string[cityList.Count];
            int index = 0;
            foreach (City city in cityList)
            {
                citiesNames[index] = city.Name;
                index++;
            }
            return citiesNames;
        }

        public List<City> GetCities()
        {
            return cityList;
        }

        public City GetCity(int index)
        {
            return cityList[index];
        }

        public int GetCityIndex(string name)
        {
            int index = 0;
            foreach (City city in cityList)
            {
                if (city.Name == name) return index;
                index++;
            }

            return -1;
        }
    }
}